package one.stand.controller;

import io.swagger.annotations.ApiOperation;
import one.stand.dto.GoodsDetailRequest;
import one.stand.model.Goods;
import one.stand.service.GoodsBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * Created by yandou on 2019/6/23.
 */
@Controller
public class WebController {

    @Autowired
    private GoodsBaseService goodsBaseService;

    @ApiOperation("商品详情")
    @GetMapping("h5/detail")
    public String detail(GoodsDetailRequest request, ModelMap modelMap) {
        Goods goodsModel = goodsBaseService.getOn(request.getId());
        if (goodsModel == null) {
            modelMap.addAttribute("detail", "商品不存在或已下架");
        } else {
            modelMap.addAttribute("detail", goodsModel.getGoodsDetails());
        }
        return "goodsDetail";
    }
}
